<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>通知公告</title> 
    <link href="${ctx }/css/base.css" rel="stylesheet">
    <link rel="stylesheet" href="${ctx }/custom/uimaker/easyui.css">
    <link href="${ctx }/css/process.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctx }/custom/uimaker/icon.css">
    <link href="${ctx }/js/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
</head> 
<body>
	<div id="d1"></div>
	<input type="hidden" id="type" value="${type}">
	<div class="easyui-tabs1" data-options="tabPosition:'right',headerWidth:120">
      <div title="基本信息" data-options="closable:false" class="basic-info">
      	<form id="dataForm" enctype="multipart/form-data">
	      	<table class="kv-table">
				<tbody>
					<tr>
						<td class="kv-label">通知标题</td>
						<td colspan="3" class="kv-content">
							<input class="easyui-textbox" name="title"
							style="height: 28px;line-height: 24px;width:400px">
						</td>
					</tr>
					<tr>
						<td class="kv-label">通知副标题</td>
						<td colspan="3" class="kv-content">
						<input class="easyui-textbox" name="smallTitle"
							style="height: 28px;line-height: 24px;width:300px">
						
						</td>
					</tr>
					<tr>
						<td class="kv-label">发布时间</td>
						<td colspan="3" class="kv-content">
						<input class="easyui-datebox" name="strDate"
							style="height: 28px;line-height: 24px;width:200px">
						
						</td>
					</tr>
					<tr>
						<td class="kv-label">通知说明</td>
						<td class="kv-content" colspan="3">
							<input type="hidden" name="context" id="context">
							<div id="editor-state" class="editor-state">
								
							</div>	
						</td>
					</tr>
					<tr>
						<td class="kv-label">选择附件</td>
						<td id="fileTd" class="kv-content" colspan="3">
							
							
							<a href="#" class="easyui-linkbutton"
							 data-options="iconCls:'icon-add'" onclick="addFiles()">添加附件</a>
						</td>
					</tr>
					<tr>
						<td class="kv-label">&nbsp;</td>
						<td align="center" class="kv-content" colspan="3">
								<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-list'" onclick="saveMessage()">保存通知</a>
								<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-back'">返回</a>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
      </div>
      <div title="查看通知" data-options="closable:false">
     		<table id="dg" title="所有通知公告"
     		 data-options="
     		 	fit:true,
     		 	rownumbers:true,
     		 	pagination:true,
     		 	striped:true,
     		 	singleSelect:true,
     		 	fitColumns:true,
     		 	url:'${ctx }/message/find'
     		 "
     		>
     			<thead>
     				<tr>
     					<th field="title" width="150">通知标题</th>
     					<th field="smallTitle" width="200">通知副标题</th>
     					<th field="createDate" align="center" width="100" data-options="
     						formatter:function(v,r,i){
     						    //2018-04-03 00:00:00
     							if(v.length>=11){
     							   v = v.substring(0,11);
     							}
     							return v;
     						}
     					">发布时间</th>
     					<th field="context" width="300">通知内容</th>
     					<th field="userId" width="80">发布人</th>
     					<th field="action" align="center" width="100" data-options="
     						formatter:function(v,r,i){
     						    var str = '<a href=\'#\''
     						    +' onclick=\'checkMessage('+r.id+')\'>查看详情</a>';
     							return str;
     						}
     					">操作</th>
     				</tr>
     			</thead>
     		</table>
	  </div>
   	  	
</body> 
</html>
    <script type="text/javascript" src="${ctx }/custom/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx }/custom/jquery.easyui.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx }/js/jquery-form.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx }/js/umeditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx }/js/umeditor/umeditor.min.js"></script>
    <script type="text/javascript" src="${ctx }/js/umeditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
	$(function(){
		var tab = $('.easyui-tabs1');
		var type = $('#type').val();
		if('1'==type ){
			tab.tabs('select','查看通知');
		}
	});

	$('#dg').datagrid({
		
	});
	
	function checkMessage(id){
		$('#d1').dialog({
			title:'查看通知详情',
			fit:true,
			modal:true,
			href:'${ctx}/message/check/'+id
		});
	}


	$('.easyui-tabs1').tabs({
      tabHeight: 36,
      fit:true
    });

     var state = UM.getEditor('editor-state');
     state.setWidth("98%");
     $(".edui-body-container").css("width", "98%");

    $(window).resize(function(){
    	setTimeout(function(){
    		$('.easyui-tabs1').tabs("resize");
	    	state.setWidth("98%");
	     	$(".edui-body-container").css("width", "98%");	
	     },1);
    }).resize();
    
    function saveMessage(){
    	var f = $('#dataForm');
    	var context = $('#editor-state').html();
    	//从富文本获取的内容赋值到隐藏域，方便form表单的获取
    	$('#context').val(context);
    	
    	var url = "${ctx}/message/add";
    	var data = f.serialize();
    	var option = {
    		type:'post',
    		url:url,
    		headers:{"ClientCallMode":"ajax"},//添加文件上传的头文件
    		dataType:'json',
    		success:function(r){
    			$.messager.alert('操作通知提示',r.msg,'info');
    			if(r.sus){
    				
    			}
    		}
    	};
    	//ajaxSubmit这个方法是由jquery-form.js提供
    	f.ajaxSubmit(option);
    }
    
    var i = 1;
    function addFiles(){
    	var str = '<div id="fileDiv'+i+'" style="text-align: left;">'+
							i+'、<input type="file" name="fileSource">'+
						'&nbsp;&nbsp;&nbsp;&nbsp;'+
						'<a href="#" style="text-decoration: none;" '+
						'onclick="javascript:$(\'#fileDiv'+i+'\').remove();">移除</a>'+
						'<hr style="margin-right: 55%"/>'+
					'</div>';
		i++;
		$('#fileTd').prepend(str);
    }
    
    
    
    
    
    
    
    
</script>
